<template>
  <el-dialog
    title="预览"
    :visible.sync="dialogVisible"
    width="90%"
    :before-close="handleClose"
    @close="handleClose"
  >
    <div id="page" class="searchresult-content-page">
      <div v-loading="loading" class="main">
        <!-- <el-button @click="$router.go(-1)" size="small" style="margin-bottom: 10px">返回</el-button> -->
        <p class="top-title">{{ studyResult.title }}</p>
        <p v-if="studyResult.subtitle" class="top-subtitle">{{ studyResult.subtitle }}</p>
        <p class="top-tip">
          <span>发布时间: </span>
          <span>{{ studyResult.createTimeStr }}</span>

        </p>
        <el-divider />
        <div
          v-if="studyResult.detail"
          class="contentRow"
          v-html="studyResult.detail.replace(/\n/gm, '<br>')"
        />
        <div v-if="pdfList && pdfList.length > 0">
          <IFrame v-for="(item, i) in pdfList" :key="i" :src="item" style="height: 1200px; width: 1200px" />
        </div>

        <VideoPlayer
          v-if="studyResult.videoUrl"
          ref="video"
          :src="studyResult.videoUrl"
          :autoplay="false"
          @onPlay="videoPlay"
        />
      </div>
    </div>
  </el-dialog>
</template>
<script>
// getNewsStudyInfo
import { getNewsStudyInfo } from '@/api/content-manage/researchResult.js'
import { formatDate } from '@/utils/index.js'
import IFrame from '@/components/iFrame/index'
import VideoPlayer from '@/components/videoPlayer'
export default {
  // 组件名称
  name: 'ViewNews',
  components: {
    IFrame,
    VideoPlayer
  },
  // 组件参数 接收来自父组件的数据
  props: {},
  // 组件状态值
  data() {
    return {
      dialogVisible: false,
      studyResult: {
        title: '',
        subtitle: '',
        createTimeStr: '',
        detail: '',
        videoUrl: '',
        pdfUrl: ''
      },
      total: 0,
      pageIndex: 0,
      loading: true,
      studentId: null,
      pdfList: []
    }
  },
  created() {
    this.init()
  },
  mounted() {
    this.init()
  },
  // 组件方法
  methods: {
    open(id) {
      this.dialogVisible = true
      this.getNewsStudyInfo(id)
    },
    async getNewsStudyInfo(id) {
      const { code, data } = await getNewsStudyInfo({ id })
      this.studyResult = {
        ...data,
        createTimeStr: formatDate(data.createTime)
      }
      if (data.pdfUrl) {
        this.pdfList = data.pdfUrl.split(',')
      }
    },
    async init() {
      setTimeout(() => {
        this.loading = false
      }, 2000)

    //   const { data, code } = await getStudentShow({ pageNo: 1, pageSize: 100 });
    },
    handleClose() {
      this.dialogVisible = false
    },
    videoPlay() {
      // const videoItem = this.$refs[`video`][0]
      // videoItem &&
      // this.imgVideoList.map((item, inx) => {
      //   if (item.type === 'video') {
      //     this.$refs[`video`][0].pause()
      //   }
      // })
    }
  }
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="scss">
.searchresult-content-page {
  position: relative;
  width: 100%;
  margin: 0 auto;

  .main {
    background: #fff;
    display: flex;
    flex-direction: column;
    align-items: center;
    .top-title {
      font-size: 30px;
      font-family: PingFangSC-Semibold, PingFang SC;
      font-weight: 600;
      color: #37383D;
      line-height: 42px;
      margin-bottom: 19px;
      margin-top: 0;
    }
    .top-subtitle {
      font-size: 22px;
      font-family: PingFangSC-Semibold, PingFang SC;
      font-weight: 600;
      color: #666;
      margin: 0;
    }
    .top-tip {
      font-size: 14px;
      font-weight: 400;
      color: #9597a0;
      line-height: 20px;
      margin-bottom: 25px;
    }
    .list {
      display: flex;
      justify-content: space-between;
      margin-bottom: 34px;
      .list-item {
        .item-title {
          font-size: 23px;
          font-weight: 500;
          color: #0c0c0c;
          line-height: 32px;
          margin-bottom: 20px;
        }
        .item-test {
          font-size: 23px;
          font-weight: 400;
          color: #0c0c0c;
          line-height: 32px;
          margin-bottom: 42px;
        }
      }
      .list-img {
        width: 464px;
        height: 298px;
      }
    }
    .video {
      width: 632px;
      height: 365px;
      margin: 30px auto 0;
      position: relative;
      .video-img {
        width: 100%;
        height: 100%;
      }
      .video-btn {
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 40%);
        position: absolute;
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
        margin: auto;
        display: flex;
        align-items: center;
        justify-content: center;
        .btn-img {
          width: 87px;
          height: 87px;
        }
      }
    }
    .bottom-nav {
      margin-top: 80px;
      display: flex;
      justify-content: space-between;
      color: #2F8EFE;
      .el-icon-arrow-left {
        margin-right: 10px;
      }
      .el-icon-arrow-right,
      .el-icon-arrow-down {
        margin-left: 10px;
      }
      .nav-item {
        position: relative;
        font-size: 18px;
        font-weight: 500;
        color: #2F8EFE;
        line-height: 33px;
        cursor: pointer;
        &.disabled {
          color: #999;
          cursor: no-drop;
        }
      }
    }
    .contentRow {
      position: relative;
      word-break: break-all;
      word-wrap: break-word;
      width: 1200px;
      img {
        max-width: 100%;
      }
    }
  }
}
.student-selecte {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  background: #fff;
  overflow-y: scroll;
  .student-item {
    position: relative;
    display: block;
    width: 100%;
    font-size: 18px;
    padding: 0 20px;
    position: relative;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: #606266;
    height: 34px;
    line-height: 34px;
    box-sizing: border-box;
    cursor: pointer;
  }
  .student-item:hover {
    background-color: #f5f7fa;
  }
}
</style>
